import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:rename_exif/main_controller.dart';
import 'package:data_table_2/data_table_2.dart';
import 'package:tuple/tuple.dart';

class InfoView extends StatelessWidget {
  const InfoView({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    var c = Get.find<MainController>();
    return Container(
        alignment: Alignment.topCenter,
        // color: Colors.grey[100],
        // padding: const EdgeInsets.all(2),
        child: Obx( () => DataTable2(
          key: UniqueKey(),
          columnSpacing: 8,
          horizontalMargin: 8,
          // showCheckboxColumn: true,
          // showBottomBorder: true,
          // minWidth: 10,
          headingRowColor: MaterialStateProperty.all(Colors.cyan[800]),
          headingRowHeight: 30,
          headingTextStyle: Theme.of(context).textTheme.subtitle1,
          dataTextStyle:  Theme.of(context).textTheme.bodyText1,
          // dataRowColor: MaterialStateProperty.all(Colors.lightGreen[50]),
          dataRowHeight: 30,
          scrollController: ScrollController(),
          lmRatio: .8,
          columns: [
            const DataColumn2(
              label: Text('属性'),
              size: ColumnSize.L,
            ),
            DataColumn2(
              label: Row(children:[
                const Expanded( child: Text('值') ),
                IconButton(
                  onPressed: () => c.copyToClipper(context),
                  icon: const Icon(Icons.file_copy, size: 18, color: Colors.amber),
                  tooltip: "复制到剪贴板"),
              ]),
              size: ColumnSize.M,
            ),
          ],
          rows: _dataRows(context, c.infoList.value),
        ))
    );
  }

  _dataRows(BuildContext context, List<Tuple3<String, String, String>> list) {
    return list.map((d){
      return DataRow2(cells: [
        DataCell(Tooltip(message: d.item2, child: Text(d.item2, overflow: TextOverflow.ellipsis))),
        DataCell(Tooltip(message: d.item3, child: Text(d.item3, overflow: TextOverflow.ellipsis))),
      ]);
    }).toList();
  }
}

